import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

###快速绘图————————————————————————————————————————————
# ##简单绘制正弦三角形
# import math
# from pylab import *
# plt.figure(figsize=(8,4))                  #创建一个绘图对象，大小为 800 *400
# x_values = arange(0.0,math.pi *4, 0.01 )   #步长0.01 初始值 0.0 终值4 Π
# y_values =sin(x_values)
# plt.plot(x_values, y_values,'b--',linewidth=1.0,label ='sin(x)')
# plt.xlabel('x')
# plt.ylabel('sin(x)')         #设置Y轴的文字
# plt.ylim(-1,1)         #显示 Y轴的范围
# plt.title('Sin')
# plt.grid(True)                #显示网格
# plt.legend()                  #显示图例(legend)
# plt.show()                    #显示图形
# plt.savefig('sin.png')        #保存文件到图片 文件sin.png




###绘制多个子图——————————————————————
# import numpy as np
# import pandas as pd
# import matplotlib.pyplot as plt
# plt.ion()  #开启交互模式
# # 画第1个图：折线图
# x=np.arange(1,100)
# plt.subplot(221)
# plt.plot(x,x*x)
# # 画第2个图：散点图
# plt.subplot(222)
# plt.scatter(np.arange(0,10), np.random.rand(10))
# # 画第3个图：饼图
# plt.subplot(223)
# plt.pie(x=[15,30,45,10],labels=list('ABCD'),autopct='%.0f',explode=[0,0.05,0,0])
# # 画第4个图：条形图
# plt.subplot(224)
# plt.bar([20,10,30,25,15],[25,15,35,30,20],color='b')
# plt.show()



###调整边框距离——————————————————————————————————————————————————
# ###(1)图标边缘的调整
# import matplotlib.pyplot as plt
#
# fig, ax = plt.subplots()
# ax.plot([1,2,3], [4,5,6])
#
# plt.subplots_adjust(left=0.2, right=0.8, top=0.8, bottom=0.2)
# plt.show()



###(2)X轴间距的调整
# import matplotlib.pyplot as plt
#
# fig, ax = plt.subplots()
# ax.plot([1,2,3], [4,5,6])
#
# ax.set_xticks([0, 1, 2])
# ax.set_xlim([-0.5, 2.5])
#
# plt.show()




##(3)图标边缘与X轴调整
# fig, ax = plt.subplots()
#
# # 绘制散点图
# x = [1, 2, 3, 4, 5]
# y = [6, 7, 8, 9, 10]
# ax.scatter(x, y)
#
# # 调整图表边缘和X轴之间的间距
# plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9)
# ax.set_xlim([0.5, 5.5])
#
# # 设置X轴刻度和标签
# ax.set_xticks([1, 2, 3, 4, 5])
# ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May'])
#
# # 设置Y轴标签和标题
# ax.set_ylabel('Y Label')
# ax.set_title('Scatter Plot')
#
# plt.show()





# #####交互式模式图表————————————————————————————————————————————————————
# import matplotlib.pyplot as plt
# import numpy as np
#
# plt.ion()  # 开启交互模式
#
# fig, ax = plt.subplots()
# x = np.linspace(0, 10, 100)
# line, = ax.plot(x, np.sin(x))
#
# for i in range(50):
#     line.set_ydata(np.sin(x + i/10.0))
#     ax.set_title(f"how2matplotlib.com - Frame {i}")
#     fig.canvas.draw()
#     fig.canvas.flush_events()
#
# plt.ioff()  # 关闭交互模式
# plt.show()





#####绘制多幅图表————————————————————————————————————————————————————————————
import matplotlib.pyplot as plt
import numpy as np

## 创建一些测试数据 -- 图1
# x = np.linspace(0, 2*np.pi, 400)
# y = np.sin(x**2)
#
# # 创建一个画像和子图 -- 图2
# fig, ax = plt.subplots()
# ax.plot(x, y)
# ax.set_title('Simple plot')
#
# # 创建两个子图 -- 图3
# f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
# ax1.plot(x, y)
# ax1.set_title('Sharing Y axis')
# ax2.scatter(x, y)
#
# # 创建四个子图 -- 图4
# fig, axs = plt.subplots(2, 2, subplot_kw=dict(projection="polar"))
# axs[0, 0].plot(x, y)
# axs[1, 1].scatter(x, y)
#
# # 共享 x 轴
# plt.subplots(2, 2, sharex='col')
#
# # 共享 y 轴
# plt.subplots(2, 2, sharey='row')
#
# # 共享 x 轴和 y 轴
# plt.subplots(2, 2, sharex='all', sharey='all')
#
# # 这个也是共享 x 轴和 y 轴
# plt.subplots(2, 2, sharex=True, sharey=True)
#
# # 创建标识为 10 的图，已经存在的则删除
# fig, ax = plt.subplots(num=10, clear=True)
#
# plt.show()



#####在图表中显示中文————————————————————————————————————————————————————————
# plt.rcParams['font.family'] = 'SimHei'  # 替换为你选择的字体
# # 创建数据
# x = [1, 2, 3, 4, 5]
# y = [2, 4, 6, 8, 10]
#
# # 绘制折线图
# plt.plot(x, y)
#
# # 添加标题和标签
# plt.title('折线图示例')
# plt.xlabel('X轴')
# plt.ylabel('Y轴')
#
# # 显示图形
# plt.show()


####——————————————————————————————————————
##(1)直方图
# # 生成随机数据
# data = pd.Series(np.random.normal(size=100))
#
# # 绘制直方图
# # bins 参数指定了直方图中的柱子数量
# plt.hist(data, bins=10)
#
# # 设置图形标题和坐标轴标签
# plt.title('RUNOOB hist() Tes')
# plt.xlabel('X-Values')
# plt.ylabel('Y-Values')
#
# # 显示图形
# plt.show()


# ##(2)饼图
# # 数据
# sizes = [15, 30, 45, 10]
# # 饼图的标签
# labels = ['A', 'B', 'C', 'D']
# # 饼图的颜色
# colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
# # 突出显示第二个扇形
# explode = (0, 0.1, 0, 0)
# # 绘制饼图
# plt.pie(sizes, explode=explode, labels=labels, colors=colors,
#         autopct='%1.1f%%', shadow=True, startangle=90)
# # 标题
# plt.title("RUNOOB Pie Test")
# # 显示图形
# plt.show()